* emacs.c (Finvocation_name): New function.
authorJim Blandy <jimb@redhat.com>
Sat, 20 Mar 1993 19:30:58 +0000 (19:30 +0000)
committerJim Blandy <jimb@redhat.com>
Sat, 20 Mar 1993 19:30:58 +0000 (19:30 +0000)
(Vinvocation_name): New variable.
(init_cmdargs): Set it.
(syms_of_emacs): defsubr Finvocation_name, staticpro and
initialize Vinvocation_name.
* lisp.h (Vinvocation_name): New extern declaration.
* xterm.c (invocation_name): Variable deleted; use
Vinvocation_name now.
(x_text_icon, x_term_init): Use Vinvocation_name now instead of
invocation_name.
(x_term_init): Don't initialize invocation_name.
(syms_of_xterm): Don't initialize or staticpro invocation_name.
* xfns.c (invocation_name): Remove extern declaration for this.
[HAVE_X11] (Fx_get_resource): Use Vinvocation_name now instead of
invocation_name.
[not HAVE_X11] (Fx_get_default): Same.

src/emacs.c
src/lisp.h
src/xfns.c
src/xterm.c

index 25edb3fc659bd9104ad023dedefef9abff95cdeb..c5b6953acfb4d71d21e6675a43aff3056aa8e242 100644 (file)
@@ -61,6 +61,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* Command line args from shell, as list of strings */
 Lisp_Object Vcommand_line_args;
 
+/* The name under which Emacs was invoked, with any leading directory
+   names discarded.  */
+Lisp_Object Vinvocation_name;
+
 /* Hook run by `kill-emacs' before it does really anything.  */
 Lisp_Object Vkill_emacs_hook;
 
@@ -155,6 +159,8 @@ init_cmdargs (argc, argv, skip_args)
 {
   register int i;
 
+  Vinvocation_name = Ffile_name_nondirectory (argv[0]);
+
   Vcommand_line_args = Qnil;
 
   for (i = argc - 1; i >= 0; i--)
@@ -164,6 +170,15 @@ init_cmdargs (argc, argv, skip_args)
          = Fcons (build_string (argv[i]), Vcommand_line_args);
     }
 }
+
+DEFUN ("invocation-name", Finvocation_name, Sinvocation_name, 0, 0, 0,
+  "Return the program name that was used to run Emacs.\n\
+Any directory names are omitted.")
+  ()
+{
+  return Fcopy_sequence (Vinvocation_name);
+}
+
 \f
 #ifdef VMS
 #ifdef LINK_CRTL_SHARE
@@ -826,6 +841,8 @@ syms_of_emacs ()
 
   defsubr (&Skill_emacs);
 
+  defsubr (&Sinvocation_name);
+
   DEFVAR_LISP ("command-line-args", &Vcommand_line_args,
     "Args passed by shell to Emacs, as a list of strings.");
 
@@ -849,4 +866,7 @@ This value is effective only if set before Emacs is dumped,\n\
 and only if the Emacs executable is installed with setuid to permit\n\
 it to change priority.  (Emacs sets its uid back to the real uid.)");
   emacs_priority = 0;
+
+  staticpro (&Vinvocation_name);
+  Vinvocation_name = Qnil;
 }
index a770636c07460782206e2f214373e0e0091ad4a1..cac35d1c00ebf66aa11f545bebebb7c7928e0851 100644 (file)
@@ -1203,6 +1203,7 @@ extern Lisp_Object Frubber_band_rectangle ();
 
 /* defined in emacs.c */
 extern Lisp_Object decode_env_path ();
+extern Lisp_Object Vinvocation_name;
 void shut_down_emacs ( /* int signal */ );
 /* Nonzero means don't do interactive redisplay and don't change tty modes */
 extern int noninteractive;
index 1f4d5751d3074e31e7ccdfe30bc242d1466feb3c..cf55cc6c3e1a5ce354ec10f4b7879b253f6682e5 100644 (file)
@@ -51,7 +51,6 @@ static XrmDatabase xrdb;
 
 /* Title name and application name for X stuff. */
 extern char *x_id_name;
-extern Lisp_Object invocation_name;
 
 /* The background and shape of the mouse pointer, and shape when not
    over text or in the modeline. */
@@ -1296,7 +1295,7 @@ and the class is `Emacs.CLASS.SUBCLASS'.")
     {
       /* Allocate space for the components, the dots which separate them,
         and the final '\0'.  */
-      name_key = (char *) alloca (XSTRING (invocation_name)->size
+      name_key = (char *) alloca (XSTRING (Vinvocation_name)->size
                                  + XSTRING (attribute)->size
                                  + 2);
       class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
@@ -1304,7 +1303,7 @@ and the class is `Emacs.CLASS.SUBCLASS'.")
                                   + 2);
 
       sprintf (name_key, "%s.%s",
-              XSTRING (invocation_name)->data,
+              XSTRING (Vinvocation_name)->data,
               XSTRING (attribute)->data);
       sprintf (class_key, "%s.%s",
               EMACS_CLASS,
@@ -1312,7 +1311,7 @@ and the class is `Emacs.CLASS.SUBCLASS'.")
     }
   else
     {
-      name_key = (char *) alloca (XSTRING (invocation_name)->size
+      name_key = (char *) alloca (XSTRING (Vinvocation_name)->size
                                  + XSTRING (component)->size
                                  + XSTRING (attribute)->size
                                  + 3);
@@ -1323,7 +1322,7 @@ and the class is `Emacs.CLASS.SUBCLASS'.")
                                   + 3);
 
       sprintf (name_key, "%s.%s.%s",
-              XSTRING (invocation_name)->data,
+              XSTRING (Vinvocation_name)->data,
               XSTRING (component)->data,
               XSTRING (attribute)->data);
       sprintf (class_key, "%s.%s",
@@ -1354,13 +1353,13 @@ The defaults are specified in the file `~/.Xdefaults'.")
   CHECK_STRING (arg, 1);
 
   value = (unsigned char *) XGetDefault (XDISPLAY 
-                                        XSTRING (invocation_name)->data,
+                                        XSTRING (Vinvocation_name)->data,
                                         XSTRING (arg)->data);
   if (value == 0)
     /* Try reversing last two args, in case this is the buggy version of X.  */
     value = (unsigned char *) XGetDefault (XDISPLAY
                                           XSTRING (arg)->data,
-                                          XSTRING (invocation_name)->data);
+                                          XSTRING (Vinvocation_name)->data);
   if (value != 0)
     return build_string (value);
   else
index c6f61668e1a1ba5d5fbf0436dafc9b77cfc1838d..35bacb748cdbd595b31caad061b0a89afa4674d1 100644 (file)
@@ -158,7 +158,6 @@ static FONT_TYPE *icon_font_info;
 
 extern Lisp_Object Vcommand_line_args;
 char *hostname, *x_id_name;
-Lisp_Object invocation_name;
 
 /* This is the X connection that we are using.  */
 
@@ -3613,7 +3612,7 @@ x_text_icon (f, icon_name)
   if (icon_font_info == 0)
     icon_font_info
       = XGetFont (XGetDefault (XDISPLAY
-                              (char *) XSTRING (invocation_name)->data,
+                              (char *) XSTRING (Vinvocation_name)->data,
                               "BodyFont"));
 
   if (f->display.x->icon_desc)
@@ -4523,8 +4522,6 @@ x_term_init (display_name)
     XSetAfterFunction (x_current_display, x_trace_wire);
 #endif /* ! 0 */
 
-    invocation_name = Ffile_name_nondirectory (Fcar (Vcommand_line_args));
-
     /* Try to get the host name; if the buffer is too short, try
        again.  Apparently, the only indication gethostname gives of
        whether the buffer was large enough is the presence or absence
@@ -4541,10 +4538,10 @@ x_term_init (display_name)
        hostname_size <<= 1;
        hostname = (char *) xrealloc (hostname, hostname_size);
       }
-    x_id_name = (char *) xmalloc (XSTRING (invocation_name)->size
+    x_id_name = (char *) xmalloc (XSTRING (Vinvocation_name)->size
                                + strlen (hostname)
                                + 2);
-    sprintf (x_id_name, "%s@%s", XSTRING (invocation_name)->data, hostname);
+    sprintf (x_id_name, "%s@%s", XSTRING (Vinvocation_name)->data, hostname);
   }
 
   /* Figure out which modifier bits mean what.  */
@@ -4642,9 +4639,6 @@ x_term_init (display_name)
 void
 syms_of_xterm ()
 {
-  staticpro (&invocation_name);
-  invocation_name = Qnil;
-
   staticpro (&last_mouse_scroll_bar);
 }
 #endif /* ! defined (HAVE_X11) */